extends RigidBody2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"

export var speed: int = 0
export var gravityScale: float = 3.5
export var hp: int = 3

onready var animated:AnimatedSprite = $AnimatedSprite



# Called when the node enters the scene tree for the first time.
func _ready():
	
	# 初始化一些参数
	
	set_linear_velocity(Vector2(speed, 0))
	set_gravity_scale(gravityScale)
	
	# 设置碰撞标志，使其触发回调
	set_contact_monitor(true)
	set_max_contacts_reported(1)
	# 也可以在右侧窗口的“节点”上手动添加信号连接
	connect("body_entered", self, "on_body_entered_event")
	pass # Replace with function body.



func _process(delta):
	print(rotation_degrees)
	if rotation_degrees < -30:
		set_rotation_degrees(-30)
		set_angular_velocity(0)
		
	if get_linear_velocity().y > 0:
		set_angular_velocity(3)
		
	if rotation_degrees > 40:
		set_angular_velocity(0)
		set_rotation_degrees(40)
		
	if Input.is_action_pressed("fly_button"):
		set_linear_velocity(Vector2(get_linear_velocity().x, -100))
		set_angular_velocity(-10)
		set_gravity_scale(0)
		animated.play()
		if not $wing.playing:
			$wing.play()
		
	if animated.frame == 5:
		animated.stop()
		animated.frame = 0
		set_gravity_scale(gravityScale)


func on_body_entered_event(other_body):
	$hit.play()
	print("hit ground!!")
	pass


